<?php
header("Content-Type: text/html; charset=utf-8");
require_once '../smarty/Smarty.class.php';
require_once '../lib/pagination.php';
require_once '../lib/query_railway.php';
require_once '../lib/base.php';

$user=$_SESSION["RU"];
if(!$user)header("Location:../user/login.php");

if($_POST["act"]=="del") {	
	$str="id=".$_POST["i"]." and (valid<=NOW() or status is NULL or status='false')";
	if($user["nick"]!="admin")$str.=" and creater='".$user["nick"]."' ";
	$op= QR::del_data($tb_bl,$str);
	if($op>0)echo "100" ;else echo "删除失败！或许数据已经被删除！";
	exit;
}
$p=($_GET["p"]==null)|($_GET["p"]==0) ?1:$_GET["p"];
$PAGE_NUM=15;
$from=($p-1)*$PAGE_NUM;

if($user["nick"]!="admin"){
	$str.=" creater = '".$user["nick"]."'";
}else{
	$nick=htmlspecialchars( $_GET["n"]);
	$status=htmlspecialchars( $_GET["s"]);	
	$str=" id>0";
	if($nick)$str.=" and creater like '%$nick%'";
	if($status)$str.=" and status='$status'";
}
$dbtable =$tb_bl;
$count=QR::get_total($dbtable, $str);
$field="*";
$str.=" order by status,creattime desc";
$data=QR::get_data($dbtable, $field,$str,$from,$PAGE_NUM);//all_data
//var_dump($data);

$smarty = new Smarty;
$smarty->assign("userdata",makedata($user["nick"],$data));
$smarty->assign("pagination", getPageNavigation($p,$count,$PAGE_NUM));
$smarty->assign("nick",$nick);
$smarty->assign("status",$status);
$smarty->assign("user",$user);
$smarty->display('bl_list.tpl');

function makedata($nick,$data){
	$nt=strtotime(date("YmdHis"));
	//$vt=strtotime($ck["valid"]);
	foreach ($data as $k=>$val) {
		$vt=strtotime($val["valid"]);
		if($nick!="admin" && $vt>$nt && $val["status"]=="true"){
			$data[$k]["m"]="false";
		}else{
			$data[$k]["m"]="true";
		}
		if($vt>$nt && $val["status"]=="true"){
			$data[$k]["d"]="false";
		}else{
			$data[$k]["d"]="true";
		}
	}
	return $data;
}
function get_status($s){
	if($s=="true")return '<font color="blue">已通过</font>';
	if($s=="false")return '<font color="red">未通过</font>';
	return '<font color="#555">未审核</font>';
}
?>